package com.zxcl.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.zxcl.domain.ProdComm;
import com.zxcl.dto.ProdCommQueryDTO;
import com.zxcl.model.Result;
import com.zxcl.service.impl.ProdCommService;
import com.zxcl.vo.ProdCommOverviewVO;
import com.zxcl.vo.ProdCommVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("评论相关接口")
@RestController
@RequestMapping("prod/prodComm/")
public class ProdCommController {

    @Autowired
    private ProdCommService prodCommService;

    @ApiOperation("分页查询评论")
    @GetMapping("page")
    @PreAuthorize(value = "hasAuthority('prod:prodComm:page')")
    public Result<Page<ProdComm>> loadProdCommPage(PageDTO pageDTO, ProdCommQueryDTO prodCommQueryDTO){
         Page<ProdComm> prodCommPage= prodCommService.loadProdCommPage(pageDTO,prodCommQueryDTO);
         return Result.success(prodCommPage);
    }

    @GetMapping("/{userId}")
    @ApiOperation("获取当前角色信息")
    public Result<ProdComm> loadMenu(@PathVariable Long userId){
        ProdComm prodComm = prodCommService.getById(userId);
        return Result.success(prodComm);
    }

    /////////////////mall////////////
    /**
     * 总评数
     * 好评
     * 中
     * 差
     * 带图
     * 好评率
     * @param prodId
     * @return
     */
    @GetMapping("prodComm/prodCommData")
    @ApiOperation("查询商品的评论总览")
    public Result<ProdCommOverviewVO> prodCommOverview(Long prodId) {
        ProdCommOverviewVO prodCommOverviewVO = prodCommService.prodCommOverview(prodId);
        return Result.success(prodCommOverviewVO);
    }


    @GetMapping("prodComm/prodCommPageByProd")
    @ApiOperation("分页查询商品的评论信息")
    public Result<Page<ProdCommVO>> prodCommMallPage(Long prodId, Integer evaluate, PageDTO pageDTO) {
        Page<ProdCommVO> prodCommVOPage = prodCommService.prodCommMallPage(prodId, evaluate, pageDTO);
        return Result.success(prodCommVOPage);
    }


}
